﻿//
//
// 版权所有 (c) 2021-2023 JR  
//
// 特此免费授予获得本软件的任何人以处理本软件的权利，但须遵守以下条件：在所有副本或重要部分的软件中必须包括上述版权声明和本许可声明。
//
// 软件按“原样”提供，不提供任何形式的明示或暗示的保证，包括但不限于对适销性、适用性和非侵权的保证。
// 在任何情况下，作者或版权持有人均不对任何索赔、损害或其他责任负责，无论是因合同、侵权或其他方式引起的，与软件或其使用或其他交易有关。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EMC.VISITOR.Core;
/// <summary>
/// 页面配置需要显示的列
/// </summary>
[SugarTable("SysPOConfigCol", "页面配置列")]
[SugarIndex("i_spocc_configpath",nameof(configPath),OrderByType.Asc)]
[SysTable]
public class SysPageOptionConfigColumn : EntityBase
{
    [SugarColumn(IsNullable = true, ColumnDescription = "路由路径")]
    public string configPath { get; set; }
    /// <summary>
    /// 列描述
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "列描述")]
    public string label { get; set; }

    [SugarColumn(IsNullable = true, ColumnDescription = "默认值")]
    public string value { get; set; }
    /// <summary>
    /// 列字段名
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "列字段名")]
    public string prop { get; set; }

    /// <summary>
    /// icon/select/checkbox
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "类型")]
    public string type { get; set; } = ColumnType.input.GetDescription();
    /// <summary>
    /// 列表列宽
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "列表列宽")]
    public int width { get; set; } = 150;
    /// <summary>
    /// 隐藏列
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "隐藏列")]
    public bool hide { get; set; } = false;
    /// <summary>
    /// 弹出表单是否显示
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "弹出表单是否显示")]
    public bool display { get; set; } = false;
    /// <summary>
    /// 参与自定义列显隐
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "参与自定义列显隐")]
    public bool showColumn { get; set; } = true;
    /// <summary>
    /// 是否是搜索框
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "是否是搜索框")]
    public bool search { get; set; } = false;
    [SugarColumn(IsNullable = true, ColumnDescription = "搜索框类型")]
    public string searchType { get; set; }

    /// <summary>
    /// 如果type=date 此值为true则是一个日期区间
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "是否日期区间")]
    public bool? searchRange { get; set; }

    /// <summary>
    /// 搜索文字宽度
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "搜索文字宽度")]
    public int searchLabelWidth { get; set; } = 150;

    [SugarColumn(IsNullable = true, ColumnDescription = "搜索框列宽")]
    public int?  searchSpan { get; set; }
    /// <summary>
    /// 列表中可编辑/返回数据中字段$cellEdit：true 合用
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = " 列表中可编辑")]
    public bool cell { get; set; } = true;


    [SugarColumn(IsNullable = true, ColumnDescription = "位置排序，数字越小位置越靠前")]
    public int order { get; set; } = 0;
    /// <summary>
    /// 列内容超出隐藏
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = " 列内容超出隐藏")]
    public bool? overHidden { get; set; } = true;

    /// <summary>
    /// 弹出表单是否禁止
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "弹出表单是否禁止")]
    public bool? disabled { get; set; }

    [SugarColumn(IsNullable = true, ColumnDescription = "固定列")]
    public bool? fixed_ { get; set; } = false;
    #region select属性
    /// <summary>
    /// 过滤条件显示列
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "过滤条件显示列")]
    public bool? filterable { get; set; }
    [SugarColumn(IsNullable = true, ColumnDescription = "是否开启虚拟Dom模式")]
    public bool? virtualize { get; set; }
    [SugarColumn(IsNullable = true, ColumnDescription = "是否为远程搜索")]
    public bool? remote { get; set; }
    /// <summary>
    /// 下拉框
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "下拉框是否多选")]
    public bool? multiple { get; set; }
    /// <summary>
    /// 如果是多选，最大选择个数
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "最大允许选择个数")]
    public int? limit { get; set; }
    [SugarColumn(IsNullable = true, ColumnDescription = "排序")]
    public bool? sortable { get; set; }
    /// <summary>
    /// 数据字典-与dicUrl/dicData配合使用
    /// 使用一：假如后端返回类型为{key,data},那这个对象的label=key,value=data
    /// 使用二：假如直接给如下dicData赋值，dicData为：{label,value},那这个对象的lable="label",value="value"
    /// </summary>
    [SugarColumn(IsJson = true, IsNullable = true, ColumnDescription = "数据字典")]
    public ColumnPropMapperInfo props { get; set; }

    /// <summary>
    /// 不向后端拉取字段，则在此字段赋值
    /// </summary>
    [SugarColumn(IsJson = true, IsNullable = true, ColumnDescription = "数据字典的值")]
    public List<ColumnProps> dicData { get; set; }
    /// <summary>
    /// 数据字典拉取地址/接口返回的key,value 必须都需要字符串，前端才能显示(最好不要用Id,用code)
    /// 如果是级联下拉框，集合中也需要放字符串，(最好不要用Id,用code)
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "数据字典拉取地址")]
    public string dicUrl { get; set; }
    /// <summary>
    /// 数据字典接口url携带请求参数
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = " 数据字典接口url携带请求参数")]
    public string dicQuery { get; set; }
    /// <summary>
    /// 数据字典接口请求方式
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "数据字典接口请求方式")]
    public string dicMethod { get; set; }

    /// <summary>
    /// 数据字典接口url返回数据格式化方法
    /// </summary>
    [SugarColumn(IsJson = true, IsNullable = true, ColumnDescription = "数据字典接口url返回数据格式化方法")]
    public string dicFormatter { get; set; }
    #endregion

    [SugarColumn(IsNullable = true, ColumnDescription = "文本最大输入长度")]
    public int? maxlength { get; set; }

    [SugarColumn(IsJson = true, IsNullable = true, ColumnDescription = "提交验证")]
    public List<Rule> rules { get; set; }

    [SugarColumn(IsNullable = true, ColumnDescription = "字段描述宽度")]
    public int? labelWidth { get; set; } = 80;
    /// <summary>
    /// 编辑/新增表单列数
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "编辑/新增表单列数")]
    public int span { get; set; } = 6;

    /// <summary>
    /// 标题提示语
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "标题提示语")]
    public string labelTip { get; set; }

    [SugarColumn(IsNullable = true, ColumnDescription = "新增时是否显示")]
    public bool? addDisplay { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "编辑时是否显示")]
    public bool? editDisplay { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "详情时是否显示")]
    public bool? viewDisplay { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "添加的时候不能修改")]
    public bool? addDisabled { get; set; } = false;
    [SugarColumn(IsNullable = true, ColumnDescription = "编辑的时候不能修改")]
    public bool? editDisabled { get; set; } = false;
    [SugarColumn(IsNullable = true, ColumnDescription = "显示字数限制")]
    public bool? showWordLimit { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "select选择框匹配")]
    public bool? searchFilterable { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "组件名称")]
    public string component { get; set; }

    [SugarColumn(IsNullable = true, ColumnDescription = "修改样式名称")]
    public string className { get; set; } = "formClassName";

    #region MyRegion
    [JsonIgnore]
    [SugarColumn(IsIgnore = true)]
    public override DateTime? CreateTime { get; set; }

    [JsonIgnore]
    [SugarColumn(IsIgnore = true)]
    public override DateTime? UpdateTime { get; set; }

    [JsonIgnore]
    [SugarColumn(IsIgnore = true)]
    public override long? CreateUserId { get; set; }

    [JsonIgnore]
    [SugarColumn(IsIgnore = true)]
    public override long? UpdateUserId { get; set; }

    [JsonIgnore]
    [SugarColumn(IsIgnore = true)]
    public override bool? cellEdit { get; set; }
    #endregion
    /// <summary>
    /// 级联选择器:可以选择任意一级
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "级联选择器:可以选择任意一级")]
    public bool? checkStrictly { get; set; }
    /// <summary>
    /// 级联选择器:可以选择任意一级(在搜索框中起作用)
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "级联选择器:可以选择任意一级(在搜索框中起作用)")]
    public bool? searchCheckStrictly { get; set; }
    /// <summary>
    /// 级联菜单展示所有层级
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "级联菜单展示所有层级")]
    [JsonProperty("show-all-levels")]
    public bool? show_all_levels { get; set; }
    #region 文件上传相关字段
    /// <summary>
    /// 上传的地址
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "上传的地址")]
    public string action { get; set; }
    /// <summary>
    /// 返回数据结构体propsHttp配置
    /// </summary>
    [SugarColumn(IsJson = true, IsNullable = true, ColumnDescription = "返回数据结构体propsHttp配置")]
    public PropsHttpModel propsHttp { get; set; }

    [SugarColumn(IsNullable = true, ColumnDescription = "日期格式化")]
    public string format { get; set; } 
    [SugarColumn(IsNullable = true, ColumnDescription = "日期值格式化")]
    public string valueFormat { get; set; }
    /// <summary>
    ///文件列表的类型 text/picture/picture-card 
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "文件列表的类型")]
    public string listType { get; set; }
    #endregion

    /// <summary>
    /// 与其它字段交互
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "与其它字段交互")]
    public string control { get; set; }

    public  SysPageOptionConfigColumn Clone()
    {
        //MemberwiseClone：返回当前对象的浅表副本(它是Object对象的基方法)
        return (SysPageOptionConfigColumn)this.MemberwiseClone();
    }
    //    control: (val, form) => {
    //            if (val === 0) {
    //              return {
    //                text2: {
    //                  display: true
    //                },
    //                text3: {
    //                  label: '内容3'
    //                }
    //              }
    //            } else
    //{
    //    return {
    //    text2:
    //        {
    //        display: false
    //                },
    //                text3:
    //        {
    //        label: '有没有发现我变了'
    //                }
    //    }
    //}
    //          },
}


public class PropsHttpModel
{
    /// <summary>
    /// 图片的根路径地址，例如返回data:{url:' / xxxx.jpg',name:''},home属性为http://xxx.com/,则最终的图片显示地址为http://xxx.com/xxxx.jpg
    /// </summary>
    public string home { get; set; }
    /// <summary>
    /// 所在sysFile表的id
    /// </summary>
    public long fileId { get; set; }
    /// <summary>
    /// 上传成功返回结构体的图片地址
    /// </summary>
    public string url { get; set; } = "url";
    /// <summary>
    /// 上传成功返回结构体的图片名称
    /// </summary>
    public string name { get; set; } = "name";
    /// <summary>
    /// 上传文件流时的名称
    /// </summary>
    public string fileName { get; set; } = "file";
    /// <summary>
    /// 返回结构体的层次
    /// </summary>
    public string res { get; set; } = "result";
}
public class ColumnPropMapperInfo
{
    public string label { get; set; }
    public string value { get; set; }
}
public class ColumnProps
{
    public string label { get; set; }
    public int value { get; set; }
}

public class Rule
{
    public bool required { get; set; } = false;
    public string message { get; set; }
    public string trigger { get; set; } = "blur";
    //rules: [{
    //          required: true,
    //          message: "请输入姓名",
    //          trigger: "blur"
    //        }]
}
public enum ColumnType
{
    [Description("icon")]
    icon,
    [Description("select")]
    select,
    [Description("switch")]
    switch_,
    [Description("number")]
    number,
    /// <summary>
    /// 日期
    /// </summary>
    [Description("date")]
    date,
    /// <summary>
    /// 日期时间（包含时分秒）
    /// </summary>
    [Description("datetime")]
    datetime,
    [Description("input")]
    input,
    [Description("textarea")]
    textarea,
    [Description("cascader")]
    cascader,
    [Description("checkbox")]
    checkbox,
    [Description("radio")]
    radio,
    [Description("time")]
    time,
    [Description("upload")]
    upload,
    [Description("img")]
    img,
    [Description("color")]
    color,
    [Description("slider")]
    slider,
    [Description("rate")]
    rate
}
